#include "fonctions_player.h"
#include "constantes_player.h"
#include <allegro.h>

controlPush convertControl(control c)
{
	if (key[c.sp])
		return controlPush::csp;
	else if (key[c.bp])
		return controlPush::cbp;
	else if (key[c.sk])
		return controlPush::csk;
	else if (key[c.bk])
		return controlPush::cbk;
	else if (key[c.pa])
		return controlPush::cpa;
	else if (key[c.u])
		return controlPush::cu;
	else if (key[c.r])
		return controlPush::cr;
	else if (key[c.l])
		return controlPush::cl;
	else if (key[c.d])
		return controlPush::cd;
	return controlPush::cnulltouch;
}
void razPile (pileControlPush *p)
{
	for (int i=0;i<HISTO_TOUCH_SIZE ;i++)
		p->touch[i]=controlPush::cnulltouch;
}
controlPush readPile(pileControlPush p, int n)
{
	return p.touch[n];
}
static void movePile(pileControlPush *p)
{
	for(int i = HISTO_TOUCH_SIZE-1; i > 0; i--)
		p->touch[i]=p->touch[i+1];
}
void addPile (pileControlPush *p, controlPush t)
{
	movePile(p);
	p->touch[0]=t;
}

bool containCombopush(bool inverseDirection, pileControlPush p, controlPush *t, int comboSize)
{
	int i =0;
	bool diff = false;
	while(i < comboSize && !diff)
	{
		diff |= (t[i] != changeDirection(inverseDirection,p.touch[comboSize-i-1]));
		i++;
	}
	return !diff;
}

void clearHistorique(player *p)
{
	for(int i=0; i < NUMBER_PLAYERS; i++)
		razPile(&(p[i].perso.fight.historique));
}

void addHistorique(player *p, controlPush c)
{
	addPile(&(p->perso.fight.historique), c);
}